/*
 * Copyright (c) 2006, 2023, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.util.Arrays;

/**
 * <p>Project: jse2302 - Ex1
 * <p>Powered by webrx On 2023-06-19 16:58:14
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Ex1 {
    public static void main(String[] args) {
        String[] ls = new String[]{"kboo","age", "eat","gea", "tea", "tan", "ate", "nat", "bat", "book", "bkoo"};
        System.out.println(Arrays.toString(ls));
        for (int i = 0; i < ls.length - 1; i++) {
            String t = ls[i];
            for (int j = i + 1; j < ls.length; j++) {
                if (is(t, ls[j])) {
                    ls[i] = ls[i].concat("-").concat(ls[j]);
                    ls[j] = "";
                }
            }
        }
        System.out.println(Arrays.toString(ls));
        String ok = "";
        for(String str : ls){
            if(!"".equals(str)){
                ok = ok.concat(str+"|");
            }
        }
        ok = ok.substring(0,ok.length()-1);

        System.out.println(ok);

        String[] oks = ok.split("\\|");
        System.out.println(oks.length);
        System.out.print("[");
        for(String str :oks){
            System.out.print(Arrays.toString(str.split("-")));
        }
        System.out.print("]");


    }

    public static boolean is(String a, String b) {
        boolean f = false;
        if ("".equals(a) || "".equals(b)) {
        } else {
            if (a.length() == b.length()) {
                var aa = a.toCharArray();
                Arrays.sort(aa);
                var bb = b.toCharArray();
                Arrays.sort(bb);
                f = new String(aa).equalsIgnoreCase(new String(bb));
            }
        }
        return f;
    }
}
